package com.zhiyou.crud.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhiyou.crud.bean.Msg;
import com.zhiyou.crud.bean.projectstype;
import com.zhiyou.crud.service.projectstypeService;

@Controller
public class projectstypeController {
@Autowired 
projectstypeService projectstypeservice;
	
/*@RequestMapping("/send")	*/
/*public String send() {
	return "pages/back/index";
	return "pages/back/classify/all_classity";
}*/	


@RequestMapping("/protype")
@ResponseBody
public Msg  protype(@RequestParam(value="pn",defaultValue="1") Integer pn) {
	PageHelper.startPage(pn,5);
	List<projectstype>	 type=projectstypeservice.getAll();
	PageInfo page=new PageInfo(type,5);
	return Msg.success().add("pageInfo", page);
}

@RequestMapping("/addType")
@ResponseBody
public Msg addType(@Valid projectstype ptype) {
			
	  int i=projectstypeservice.addType(ptype);
	  if(i>0) {
		  return Msg.success();
	  }
	  else {
		  return Msg.fail();
	  }
	}

@RequestMapping("/getType/{id}")
@ResponseBody
public Msg getType(@PathVariable("id") Integer id) {
	 projectstype     pstype=projectstypeservice.getType(id);
	 return  Msg.success().add("pstype",pstype);
}

@RequestMapping("/updateType")
@ResponseBody
public Msg  updateType(projectstype pro) {
	int  i=projectstypeservice.updateType(pro);
	if(i>0) {
		return Msg.success();
	}else {
		return Msg.fail();
	}
	  
}

@RequestMapping("/deleteType/{id}")
@ResponseBody
public  Msg  deleteType (@PathVariable("id") Integer id) {
	int i=projectstypeservice.deleteType(id);
	if(i>0) {
		return Msg.success();
	}else {
		return Msg.fail();
	}
}
}








